// 集成PageOffice实现在线打开文件的自定义组件
import React, { useState, useEffect } from 'react';

// PageOffice的初始化事件回调函数，您可以在这里添加自定义按钮
function OnPageOfficeCtrlInit() {
    window.pageofficectrl.AddCustomToolButton("保存", "SaveFile()", 1);
}
// 自定义“保存”按钮执行的函数
function SaveFile(){
    window.pageofficectrl.WebSave();
}
// 把PageOffice的相关函数挂载到window对象
window.OnPageOfficeCtrlInit = OnPageOfficeCtrlInit;
window.SaveFile = SaveFile;


function Doc() {
  const [data, setData] = useState(null);

  useEffect(() => {
    fetch('/api/SimpleWord/Word') // 请求后端api打开文件
      .then(response => {
        if (!response.ok) {
          throw new Error('Network response was not ok');
        }
        return response.text(); 
      })
      .then(data => {
        setData(data); 
      })
      .catch(error => {
        console.error('There has been a problem with your fetch operation:', error);
      });
  }, []); 

  return (
    <div className="poDiv" dangerouslySetInnerHTML={{ __html: data ? data : "loading..." }} />
  );
}

export default Doc;

